<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {margin: 0;overflow: hidden;}
    #canvas {background-color: antiquewhite;}
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>
  <script>
    /** @type {HTMLCanvasElement} */
    const canvas = document.querySelector('#canvas');
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    const ctx = canvas.getContext('2d');
    ctx.lineWidth = 40;

    /*
      1.建立图像源
      图像<img>
      视频<video>
      canvas
    */
    const img = new Image();
    img.src = './images/floor.jpg';
    img.onload = function () {
      /* 
        2.建立纹理对象，定义重复方式及
        context.createPattern(image, "repeat|repeat-x|repeat-y|no-repeat")
      */
      const pat = ctx.createPattern(img, 'repeat');
      ctx.fillStyle = pat;
      ctx.fillRect(0,0,canvas.width,canvas.height);
    }
    
  </script>
</body>
</html>